<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Registration extends CI_Controller {
	function __construct()
	{
		parent::__construct();
        $this->load->model("customers_model", "model", TRUE);

	}

	public function index()
	{
		$data['item'] =$this->model->get_record(0);
		$data['title_options']= array("Mr"=>"Mr", "Mrs"=>"Mrs", "Miss"=>"Miss", "Ms"=>"Ms", "Dr"=>"Dr");
        $data['countries'] = $this->model->get_options("all_countries", "country", "country", "Select your country", "", "country") ;
        $this->template->set("title", "Customer Registration");
		$this->template->load("registration/registration_view", $data);
	}

	function register()
	{
		$this->load->library("form_validation");
        $this->form_validation->set_rules("firstname", "First Name", "trim|required");
        $this->form_validation->set_rules("address", "Address", "trim|required");
		$this->form_validation->set_rules("city", "City", "trim|required");
        $this->form_validation->set_rules("state", "State", "trim|required");
        $this->form_validation->set_rules("country", "Country", "trim|required");
        $this->form_validation->set_rules("phone", "Telephone number", "trim|required");
        $this->form_validation->set_rules("email", "Email", "trim|required|valid_email");

		$this->form_validation->set_rules("username", "Username", "trim|alpha_dash|required");
		$this->form_validation->set_rules("pwd", "Password", "required|min_length[6]|matches[re_pwd]");


		if($this->form_validation->Run()===FALSE)
		{
			$data['error'] = validation_errors();
		}
		else{
            $data = $this->model->register_customer();
			if(isset($data['success']))
			{
				$data['list'] = "&nbsp;";
				$data['reset'] = true;
			}
		}

		$this->util->send_json($data);
	}





}

/* End of file registration.php */
/* Location: ./application/controllers/registration.php */